package com.zhuang.principle.ocp;

/**
 * @Classname OpenClosed1
 * @Description 开闭原则的错误示范
 * @Date 2021/3/15 14:29
 * @Created by dell
 */

public class OpenClosed1 {
    public static void main(String[] args) {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Triangle());
    }
}
class GraphicEditor{
    public void drawShape(Shape s){
        if (s.m_type==1){
            drawRectangle(s);
        }
        if (s.m_type==2){
            drawCircle(s);
        }
        if (s.m_type==3){
            drawTriangle(s);
        }
    }

    public void drawRectangle(Shape shape){
        System.out.println("绘制矩形...");
    }
    public void drawCircle(Shape shape){
        System.out.println("绘制圆形...");
    }
    //新增的一个三角形
    public void drawTriangle(Shape shape){
        System.out.println("绘制三角形...");
    }

}

class Shape{
    int m_type;
}
//矩形
class Rectangle extends Shape{
    Rectangle(){
        super.m_type=1;
    }
}
//圆形
class Circle extends Shape{
    Circle(){
        super.m_type=2;
    }
}
//三角形
class Triangle extends Shape{
    Triangle(){
        super.m_type=3;
    }
}
